﻿using Manon.Admin.Web.ApplicationCore.Dtos.Role;
using Manon.Admin.Web.ApplicationCore.Interfaces;
using Manon.Admin.Web.Models;
using Manon.Autofac;
using Manon.Core.Commons;
using Manon.Core.Extensions;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Manon.Admin.Web.Controllers
{
    public class RoleController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Edit()
        {
            return View();
        }
        [Authorize]
        [HttpPost]
        public async Task<IPagedList<RoleOutput>> GetRolePageList([FromBody] GetRolePageListInput Input)
        {

            var user = Resolver.Resolve<IRoleService>();
            var result = await user.GetRolePageList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveRole([FromBody] SaveRoleInput Input)
        {
            var role = Resolver.Resolve<IRoleService>();
            var result = await role.SaveRole(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<RoleOutput> GetRole(int RoleId)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetRoleById(RoleId);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetEnabled([FromBody] SetRoleEnabledInput Input)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.SetEnabled(Input);
            return result;
        }


        [Authorize]
        [HttpGet]
        public async Task<List<SimpleRoleOutput>> GetSimpleRoleList()
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetSimpleRoleListAsync();

            return result;
        }



      


        [Authorize]
        [HttpPost]
        public async Task<Result> BandRoleMenus([FromBody] BandRoleMenusInput Input)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.BandRoleMenus(Input);
            return result;
        }

        [Authorize]
        [HttpGet]
        public async Task<List<string>> GetRoleMenuIds(int RoleId)
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetRoleMenuIds(RoleId);
            return result;
        }


        [Authorize]
        [HttpGet]
        public async Task<List<string>> GetUserMenuButtonIds()
        {

            var role = Resolver.Resolve<IRoleService>();
            var result = await role.GetUserMenuButtonIds();
            return result;
        }

        /// <summary>
        /// 虎丘所有菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Menu>> GetAllMenu()
        {
            string filePath = Directory.GetCurrentDirectory().Replace("\\", "/");

            List<Menu> menus = JsonHelper.Read<List<Menu>>($@"{filePath}/Config/menu.json");

            return await Task.FromResult(menus);
        }
    }
}
